package com.aqie.rabbit.test;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;


/**
 * 程序正常执行办法
 * 1. while 循环添加输出语句
 * 2. flag 添加 volatile 关键字
 */
@Slf4j
public class VolatileExample extends Thread {
    // 设置类静态变量,各线程访问这同一共享变量
    private static boolean flag = false;

    @Override
    public void run() {
        super.run();
        while (!flag) {
            log.info("flag is false");
        }
        //StringUtils
    }

    public static void main(String[] args) throws InterruptedException {
        // testMultiThread();

        /*int a,b,c = 0;
        a = b = 1;
        if (c == 0) b = 2;
        log.info("{}",b);*/

        /*for (int i = 0; i < 1000; i++) {
            new Thread(new MyRunnable()).start();
        }*/

    }

    private static void testMultiThread() throws InterruptedException {
        new VolatileExample().start();
        // sleep的目的是等待线程启动完毕,也就是说进入run的无限循环体了
        Thread.sleep(1000);
        flag = true;
        log.info("flag is true");
    }
}
